
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:include page="/WEB-INF/views/layouts/header.jsp" />
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 网站地址
String netPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
<script type="text/javascript">
/**
	把指定的一组checkbox所选的值构造为逗号分隔的字符串
*/
function getAllValue(group_box) {
	var boxes = document.getElementsByName(group_box);alert(boxes[i].value);
	var values = "55,";
	for (var i = 0; i < boxes.length; i++) {
		if (boxes[i].checked) {
			values += boxes[i].value + ",";
		}
	}
	if (values.length > 0) {
		values = values.substring(0, values.length - 1);
	}
	return values;
}
/**
 *	全选复选框或者是全取消复选框的选择
 */
function selectAll(all_box, group_box) {
	
	var main_checkbox = document.getElementById(all_box);
	var sub_boxes = document.getElementsByName(group_box);
	
 	for (var i = 0; i < sub_boxes.length; i++) {
		if (main_checkbox.checked) {
			sub_boxes[i].checked = true;
		} else {
			sub_boxes[i].checked = false;
		}
	}
	
	// 20140211 add by xy start..
	chooseColumn("columnRole");
	// 20140211 add by xy end .. 
}
/**
	提交之前的校验
*/
function validateSubmit(obj){
	var message = "";
	$("[data-required='true']",obj).each(function(){
		var value = $(this).val();
		if(!value){
			var nullMessage = $(this).attr("null-message");
			message+=nullMessage+"\n";
		}
	});
	$("[data-type='lengthLimit']",obj).each(function(){
		var limitLength = $(this).attr("data-length");
		var value =  $(this).val();
		if(value){
			if(value.length>limitLength){
				message+=$(this).attr("message")+"\n";
			}
		}
	});
	if(message){
		alert(message);
		return false;
	}else{
		return true;
	}
}
/**
	获取提交的数据
*/
function getParams(table){
	var params = "";
	var id = $("[name*='groupId']",table).val();
	if(id){
		params+="groupId="+id;
	}
	var groupName = $("[name*='groupName']",table).val();
	if(groupName){
		params+="&groupName="+groupName;
	}
	var groupDescr = $("[name='groupDescr']",table).val();
	if(groupDescr)
		params+="&descr="+groupDescr;
	var ruleIndex=0;
	$("[name*='group_box']",table).each(function(index){
		//if($(this).attr("checked")==="checked"){
		if($(this).attr("checked")){
			params+="&operatorRulesList["+ruleIndex+"].ruleId="+$(this).val();
			ruleIndex++;
		}
	});
	// 20140211 add by xy  start...
	params += "&relatedColumns="+$("#strRelatedColumns").val();
	// 20140211 add by xy  end...
	return params;
}

/**
 *	修改角色
 */
function update(obj){
	var table = $(obj).parent().parent().children("table");
	var params=getParams(table);
	params=params+"&operatorRulesList[1].ruleId=55";
	if(validateSubmit(table)){
		$.ajax({
		  url: "<%=basePath%>account/updateRoleSave",
		  type:"POST",
		  contentType:"application/x-www-form-urlencoded; charset=utf-8",
		  data:params,
		  dataType: 'text',
		  success: function(data) {
			 var jsonobj=eval('('+data+')');
			 if(jsonobj.state==='1'){
				 alert(jsonobj.result);
				 window.location='<%=basePath%>account/role';
			 }else if(jsonobj.state==='0'){
				 alert(jsonobj.result);
			 }
		  },
		  error: function(XMLHttpRequest, textStatus, errorThrown) {
				 alert("修改失败！");
		  }
		});
	}
};


// 20140211 add by xy start..
// 栏目选择框
function chooseColumn(obj){

	if($("#" + obj).attr("checked")) {
		var url = '<%=basePath%>account/chooseColumn?relatedColumns='+$("#strRelatedColumns").val();
		var HTML = '<div class="Popup">';
		HTML += '<div class="Popupheader"><a node-type="close" href="#"><img src="<%=basePath%>/images/Popupclose01.png" width="28" height="28"></a></div>';
		HTML += '<div class="Popup_A"><div class="Popup_A_1">';
				HTML += '<div class="Popup_title">选择关联栏目</div>';
				HTML += '<iframe width="100%" height="400" src="'+ url +'" scrolling="no" frameborder="0"></iframe>';
				HTML += '</div></div>'
				HTML += '<div class="Popupfoot"><img src="<%=basePath%>images/Popupbg01_footer.png" width="550" height="15"></div></div>';
		$.dialog({skin:false,content:HTML});
	} else {
		$("#strRelatedColumns").val(",");
	}
};
// 20140211 add by xy end..

</script>

<!--中间部分开始-->
<div class="main">
	<!-- 左侧 -->
	<jsp:include page="/WEB-INF/views/account/sidebar.jsp" />
	<!-- /左侧 -->
	<!-- 核心内容区域 -->
	<div id="iaas_layout_content" class="rightblock">
		<p class="shadow"></p>
		<div class="content">
			<!--默认状态下引用样式ml60，展开后引用样式ml140-->
			<div class="mainblock">
				<div class="tabA">
					<h1>
						角色修改
					</h1>
				</div>
				<table width="100%" border="0" cellpadding="0" cellspacing="0"
					class="jsgltable mt10">
					<tr>
						<td width="8%" valign="top">
							<p>
								角色名称：
							</p>
						</td>
						<td width="92%" valign="top">
							 <input name="groupId" type="hidden" value="${operatorGroups.groupId}"/>
							<input name="groupName" type="text" id="textfield"
								data-type="lengthLimit" data-required="true" data-length="60"
								null-message="角色名称不能为空 ！" message="角色不允许超过60个字符！"
								placeholder="输入您要创建的角色名称" class="jsmc" value="${operatorGroups.groupName}">
						</td>
					</tr>
					<tr>
						<td valign="top">
							<p>
								角色说明：
							</p>
						</td>
						<td valign="top">
							<textarea name="groupDescr" id="textfield2"
								data-type="lengthLimit" data-length="100"
								message="角色说明不允许超过100个字符！" placeholder="对您定义的角色描述一下吧">${operatorGroups.descr}</textarea>
						</td>
					</tr>
					<tr>
						<td valign="top">
							<p>
								权限选择：
							</p>
						</td>
						<td>
							<ul>
								<li>
									<input type='checkBox' id='all_box' onclick='selectAll( "all_box", "group_box");'/>
									全选
								</li>
								<div class="clear"></div>
							</ul>
							<ul>
								<c:forEach items="${operatorRulesList}" var="operatorRule">
									<!--  20140211 add by xy start... -->
									<c:choose>
										<c:when test="${operatorRule.ruleId==chooseColumn}">
											<li>
												<input name="group_box" type="checkbox"
													value="${operatorRule.ruleId}" id="columnRole"
													onchange="chooseColumn('columnRole')">${operatorRule.ruleName}&nbsp;<a href="#" onclick="chooseColumn('columnRole')">查看</a>
											</li>
										</c:when>
										<c:when test="${operatorRule.ruleId==59}">
								    		 <li><input name="group_box" type="checkbox" value="${operatorRule.ruleId}">  
								     			 ${operatorRule.ruleName}
								    		</li>
								    	</c:when>
										 <%-- <c:otherwise>
											<!--  20140211 add by xy end... -->
											<li>
												<input name="group_box" type="checkbox"
													value="${operatorRule.ruleId}">
												${operatorRule.ruleName}
											</li>
											<!--  20140211 add by xy start... -->
										</c:otherwise> --%>
									</c:choose>
									<!--  20140211 add by xy end... -->
								</c:forEach>
							</ul>
							<!--  20140211 add by xy start... -->
							<!-- 栏目字符串  -->
							<input type="hidden" name="strRelatedColumns" id="strRelatedColumns" value="${operatorGroups.relatedColumns}"></input>
							<!--  20140211 add by xy end... -->
						</td>
					</tr>
				</table>
				<div class="btnblock ">
					<input name="Input" type="button" value="修改" onclick="update(this);" style="cursor: pointer"
						class="btngreen01 linkhand" />
				</div>
			</div>
		</div>
	</div>
</div>
<c:forEach items="${operatorGroups.operatorRulesList}"
	var="operatorRuleSelected">
	<script type="text/javascript">
	var selectedRule = '${operatorRuleSelected.ruleId}';
	$("[value='" + selectedRule + "']").attr("checked", "checked");
</script>
</c:forEach>
<!--中间部分结束-->
<!--底部开始-->
<jsp:include page="/WEB-INF/views/layouts/footer.jsp" />
<!--底部结束-->

</body>
</html>
